package books.borrowing;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import books.borrowing.bo.IAuthorManagerClientService;
import books.borrowing.bo.IBookBorrowingBo;
import books.borrowing.bo.IBookManagerClientService;
import books.borrowing.bo.ISubscriberBo;

public class EJBFacade {
	private static volatile EJBFacade instance = null;

	private static ApplicationContext _appContext;

	public final static EJBFacade getInstance() {
		if (EJBFacade.instance == null) {
			synchronized (EJBFacade.class) {
				if (EJBFacade.instance == null) {
					EJBFacade.instance = new EJBFacade();
				}
			}
		}
		return EJBFacade.instance;
	}

	public EJBFacade() {
		super();
		_appContext = new ClassPathXmlApplicationContext(
				"spring/config/BeanLocations.xml");
	}

	@SuppressWarnings("static-access")
	public static ISubscriberBo getSubscriberBo() {
		return (ISubscriberBo) getInstance()._appContext.getBean("subscriberBo");
	}
	
	@SuppressWarnings("static-access")
	public static IBookBorrowingBo getBookBorrowingBo() {
		return (IBookBorrowingBo) getInstance()._appContext.getBean("rentBo");
	}
	
	@SuppressWarnings("static-access")
	public static IBookManagerClientService getBooksManager() {
		return (IBookManagerClientService) getInstance()._appContext
				.getBean("bookManagerClientServiceImpl");
	}

	@SuppressWarnings("static-access")
	public static IAuthorManagerClientService getAuthorManager() {
		return (IAuthorManagerClientService) getInstance()._appContext
				.getBean("authorManagerClientServiceImpl");
	}
}
